package com.gaojx.lang.aop;

import com.gaojx.lang.form.ElementForm;
import com.gaojx.lang.form.TableViewForm;
import javafx.scene.control.Tab;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.xml.bind.Element;

/**
 * @author junxiang.gao
 * @since 2020/8/28
 */
@Aspect
@Component
public class ParamConverterAspect {

    private static final Logger LOGGER = LoggerFactory.getLogger(ParamConverterAspect.class);

    @Pointcut("execution(* com.gaojx.lang.rule..*Controller.testType(..))")
    public void paramConverter() {
    }

    @Around("paramConverter()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object[] args = proceedingJoinPoint.getArgs();

        Object arg = args[0];

        ElementForm form;
        if (arg instanceof ElementForm) {
            form = (ElementForm) arg;
        } else {
            throw new RuntimeException("Wrong args");
        }
        LOGGER.info("接收参数 elementForm: {}", form);

        return proceedingJoinPoint.proceed(args);
    }
}
